Skip to content

fix round() handling of scale, precision, and nulls#2187

Merged
jycor merged 11 commits intomainfrom
james/round
Dec 6, 2023
Merged

fix round() handling of scale, precision, and nulls#2187
jycor merged 11 commits intomainfrom
james/round

Conversation

@jycor
Copy link
Copy Markdown
Contributor

@jycor jycor commented Dec 6, 2023

This PR has ROUND() behavior match MySQL more closely specifically when handling NULLs.
Additionally, it refactors the function to no longer use custom logic, and rely on decimal.Decimal library for conversions.

The slowness from the original issues stems from the math.Pow() function that is attempting to raise precision to some huge negative number. This PR solves that problem by constraining the precision values to our DecimalMaxScale (30).
A better constraint would be -308 since that's the max scale of a float supported by MySQL. However, we don't go nearly as far. If we knew the scale of the passed in value we could also constrain the precision that way.

This PR also rewrites the ROUND() unit tests to be structured like other unit tests for functions, and fixes their handling of null arguments.

fixes: dolthub/dolt#7073

Copy link
Copy Markdown
Contributor

@max-hoffman max-hoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks OK, the variable naming in Round.Eval() kind of makes it kind of hard to tell what's going on though

@jycor jycor merged commit dfa9ab6 into main Dec 6, 2023
@jycor jycor deleted the james/round branch December 6, 2023 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential Issue Using ROUND

2 participants